package com.tc.infinitechat.authenticationservice.utils;

import cn.hutool.core.util.StrUtil;
import io.minio.GetPresignedObjectUrlArgs;
import io.minio.MinioClient;
import io.minio.http.Method;
import lombok.SneakyThrows;
import org.hibernate.validator.internal.constraintvalidators.bv.time.past.PastValidatorForYear;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.print.DocFlavor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName OssUtils
 * @Author 大马鲛鱼丸Gaga
 * @Description TODO
 * @Date 2025/10/8 21:55
 */
@Component
public class OssUtils {
    @Resource
    private MinioClient minioClient;

    @Value("${minio.url}")
    private String url;

    @SneakyThrows
    public String uploadUrl(String bucketName, String objectName, Integer expires) {
        return minioClient.getPresignedObjectUrl(
                GetPresignedObjectUrlArgs.builder()
                .method(Method.PUT).bucket(bucketName)
                .object(objectName)
                .expiry(expires, TimeUnit.SECONDS)
                .build());
    }

    public String downUrl(String bucketName, String fileName) {

        return url + StrUtil.SLASH + bucketName + StrUtil.SLASH + fileName;
    }
}
